package com.module.antiFake;

import java.util.HashMap;
import java.util.Map;

import com.module.antiFake.manager.AntiFakeWarnManager;
import com.module.antiFake.vo.AntiFakeWarn;
import com.module.sys.LoginSession;

import base.util.ConstantUnit;
import base.util.Page;

public class AntiFakeWarnService {
	public Page toList(AntiFakeWarn warn,final Integer start,final Integer limit) throws Exception{
		Page page = new Page();
        page.setStart(start);
        page.setLimit(limit);
        warn.setOrgid(LoginSession.getOrgid());
        AntiFakeWarnManager antiFakeWarnManager = AntiFakeWarnManager.getInstance();
        page = antiFakeWarnManager.findWarnFromWebSearch(warn, page);
        return page;
	}
	public AntiFakeWarn getNextAntiFakeWarn(Long id)throws Exception{
		AntiFakeWarn warn = new AntiFakeWarn();
		warn.setId(id);
		warn.setOrgid(LoginSession.getOrgid());
	   	AntiFakeWarnManager antiFakeWarnManager = AntiFakeWarnManager.getInstance();
	   	return antiFakeWarnManager.getNextAntiFakeWarn(warn);	        
	}
//	/**
//	 * 返回企业未处理预警次数;
//	 * @param orgId
//	 * @return
//	 * @throws Exception
//	 */
//	public Long getOrganizationWarnMessageCount() throws Exception{
//		Map<String,Object> map = new HashMap<String,Object>();
//        map.put(ConstantUnit.O_PT, "getOrganizationWarnMessageCount");
//        AntiFakeWarn warn = new AntiFakeWarn();
//        warn.setOrgid(LoginSession.getOrgid());
// 	    map.put("antiFakeWarn", warn);
//		return AntiFakeSocketClient.returnValue(map).getAntiFakeWarn().getUntreatedNum();
//	}
//	
	/**
	 * 根据id查询预警信息
	 * @param id
	 * @return 
	 */
	public AntiFakeWarn findById(Long id){
		AntiFakeWarn warn = new AntiFakeWarn();
        try {
        	AntiFakeWarnManager antiFakeWarnManager = AntiFakeWarnManager.getInstance();
        	warn = antiFakeWarnManager.findById(id);
        	return warn;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	/**
	 * 处理预警信息
	 * @param id
	 * @return
	 */
	public Boolean processComplete(Long id){
		Short processState = AntiFakeWarn.PROCESS_STATE_COMPLETE;
		return updateProcessState(id,processState);
	}
	/**
	 * 不处理预警信息
	 * @param id
	 * @return
	 */
	public Boolean processFail(Long id){
		Short processState = AntiFakeWarn.PROCESS_STATE_FAIL;
		return updateProcessState(id,processState);
	}
	
	private Boolean updateProcessState(Long id,Short processState) {
		AntiFakeWarn warn = new AntiFakeWarn();
		warn.setId(id);
		warn.setProcessState(processState);
		warn.setProcessId(LoginSession.getUserid());
		warn.setProcessName(LoginSession.getUsername());
        try {
        	AntiFakeWarnManager antiFakeWarnManager = AntiFakeWarnManager.getInstance();
        	return antiFakeWarnManager.updateAntiFakeWarnProcessState(warn);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
}
